package com.ky.homestay.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ky.erp.common.annotation.ControllerOperateLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import com.ky.homestay.pojo.entity.User;
import com.ky.homestay.service.IUserService;
import com.ky.common.pojo.qo.PageQO;
import com.ky.common.pojo.vo.PageResult;
import com.ky.common.pojo.vo.ResultInfo;
import org.springframework.beans.factory.annotation.Autowired;
import javax.validation.Valid;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 用户 前端控制器
 * </p>
 *
 * @author kuangyu
 * @since 2025-03-11
 */
@Validated
@Api(tags = "用户")
@Controller
@RequestMapping("/homestay/user")
public class UserController {

    @Autowired
    private IUserService userService;

    @ApiOperation("进入用户管理页面")
    @GetMapping("initUser")
    public String initUser(){
        return "/homestay/user";
    }
/*
    @ApiOperation("分页查询用户")
    @PostMapping("findUser")
    @ResponseBody
    public PageResult<User> findUser(UserQO qo){
        QueryWrapper<User> wrapper = new QueryWrapper<User>();
        wrapper.lambda()
        ;
        return userService.findByPage(qo, wrapper);
    }
*/
    @ControllerOperateLog("增加/修改用户")
    @ApiOperation("增加/修改用户")
    @PostMapping("updateUser")
    public @ResponseBody ResultInfo updateUser(@Valid @RequestBody User user){
        return ResultInfo.flag(userService.saveOrUpdate(user));
    }

    @ControllerOperateLog("删除用户")
    @ApiOperation("删除用户")
    @GetMapping("deleteUser")
    public @ResponseBody ResultInfo deleteUser(@RequestParam("id") Long id){
        return ResultInfo.flag(userService.removeById(id));
    }

}
